package com.app.micaihu.view.login.dialog

import android.content.Context
import com.app.base.BaseDialog
import com.app.micaihu.R
import com.app.micaihu.view.bean.AccountConflict
import com.app.micaihu.view.utils.loadCircleImage
import com.app.micaihu.view.utils.loadImage
import kotlinx.android.synthetic.main.login_bind_account_conflict_dialog.*

/**
 * 账号冲突 弹框
 */
class AccountConflictDialog(context: Context, user: AccountConflict) : BaseDialog(context) {

    override fun getLayoutId() = R.layout.login_bind_account_conflict_dialog
    var user: AccountConflict? = null

    var currentSelect = true

    init {
        this.user = user
        this.setCanceledOnTouchOutside(false)
        this.setCancelable(false)
    }

    override fun setData() {
        user?.let { user ->
            user.currentUser?.let {
                ivHeadPic.loadCircleImage(it.headPic, R.mipmap.image_default_round)
                tvNickName.text = it.nickName
                tvMilitaryTime.text = it.militaryTime
                tvScore.text = it.score
                tvGold.text = it.gold

                ivRankIcon.loadImage(it.rankIcon)
                tvRankName.text = it.rankName
                tvRegisterTime.text = it.registerTime
                tvClashDesc.text = it.clashDesc
            }
            user.clashUser?.let {
                ivHeadPicOther.loadCircleImage(it.headPic, R.mipmap.image_default_round)
                tvNickNameOther.text = it.nickName
                tvMilitaryTimeOther.text = it.militaryTime
                tvScoreOther.text = it.score
                tvGoldOther.text = it.gold

                ivRankIconOther.loadImage(it.rankIcon)
                tvRankNameOther.text = it.rankName
                tvRegisterTimeOther.text = it.registerTime
                tvClashDescOther.text = it.clashDesc
            }
        }
    }

    override fun addListeners() {
        rlCurrent.setOnClickListener {
            currentSelect = true
            rlCurrent.setBackgroundResource(R.drawable.account_conflict_on_bg)
            rlOther.setBackgroundResource(R.drawable.account_conflict_off_bg)
        }
        rlOther.setOnClickListener {
            currentSelect = false
            rlOther.setBackgroundResource(R.drawable.account_conflict_on_bg)
            rlCurrent.setBackgroundResource(R.drawable.account_conflict_off_bg)
        }
        tvOk.setOnClickListener {
            dismiss()
            mOnClickListener?.onOk(currentSelect)
        }
        tvCancel.setOnClickListener {
            dismiss()
            mOnClickListener?.onCancel()
        }
    }

    interface OnClickListener {
        fun onOk(currentSelect: Boolean)
        fun onCancel()
    }

    var mOnClickListener: OnClickListener? = null

    fun setOnClickListener(onClickListener: OnClickListener) {
        this.mOnClickListener = onClickListener
    }
}